package day29;

import day26.DBUtil;

import java.sql.*;

public class Text1 {
    //统计各种性别的人数，并输出
    public static void main(String[] args) {
        Connection connection = null;
        ResultSet resultSet = null;
        PreparedStatement preparedStatement = null;
        try {
            connection = DBUtil.getConnection();
            String sql = "select sex, count(stuno) from s_student group by sex";
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                String sex=resultSet.getString("sex");
                int count = resultSet.getInt("count(stuno)");
                System.out.println(sex+"    "+  count + "人");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DBUtil.close(resultSet);
            DBUtil.close(preparedStatement);
            DBUtil.close(connection);
        }
    }
}